/**
 * ConstantValues.cpp (Singleton pattern)
 */

#include "include/constantvalues.h"

bool ConstantValues::instanceFlag=false;
ConstantValues* ConstantValues::single=NULL;

ConstantValues::ConstantValues()
{
	filters=Value(objectValue);
	qdiscs=Value(objectValue);
	classes=Value(objectValue);

	//Constant values
	//Filters:
	//U32:
	//Add filter
	filters["name"]="filter types";
	filters["enum"]=1;
	filters["u32"]["name"]="priority";
	filters["u32"]["text"][1]="filter add dev";
	//Device
	filters["u32"]["value"][1]="device";
	filters["u32"]["text"][2]="protocol ip parent";
	//Parent id
	filters["u32"]["value"][2]="parent id";
	filters["u32"]["text"][3]="prio";
	//filter priority
	filters["u32"]["value"][3]="filter priority";
	filters["u32"]["text"][4]="u32";
	//filters["u32"]["add_end"]["text"][1]="flowid";
	//filters["u32"]["add_end"]["value"][1]="flow id";

	//Source IP match
	filters["u32"]["0src_ip"]["name"]="source IP address";
	filters["u32"]["0src_ip"]["text"][1]="match ip src";
	filters["u32"]["0src_ip"]["value"][1]="ip addr";
	//filters["u32"]["src_ip"]["text"][2]="0xffff";
	//Destination IP match
	filters["u32"]["1dst_ip"]["name"]="destination IP address";
	filters["u32"]["1dst_ip"]["text"][1]="match ip dst";
	filters["u32"]["1dst_ip"]["value"][1]="ip addr";
	//filters["u32"]["1dst_ip"]["text"][2]="0xffff";


	filters["u32"]["protocols"]["name"]="protocols";
	filters["u32"]["protocols"]["enum"]="1";
	//TCP protocol
	filters["u32"]["protocols"]["tcp"]["name"]="tcp";
	filters["u32"]["protocols"]["tcp"]["text"][1]="match ip protocol 6 0xff";
	//TCP source port match
	filters["u32"]["protocols"]["tcp"]["src_port"]["name"]="source port";
	filters["u32"]["protocols"]["tcp"]["src_port"]["text"][1]="match ip sport";
	filters["u32"]["protocols"]["tcp"]["src_port"]["value"][1]="port";
	filters["u32"]["protocols"]["tcp"]["src_port"]["text"][2]="0xff";
	//TCP destination port match
	filters["u32"]["protocols"]["tcp"]["dst_port"]["name"]="destination port";
	filters["u32"]["protocols"]["tcp"]["dst_port"]["text"][1]="match ip dport";
	filters["u32"]["protocols"]["tcp"]["dst_port"]["value"][1]="port";
	filters["u32"]["protocols"]["tcp"]["dst_port"]["text"][2]="0xff";
	//TCP control bits match
	filters["u32"]["protocols"]["tcp"]["tcp_control_bits"]["name"]="TCP control flags";
	filters["u32"]["protocols"]["tcp"]["tcp_control_bits"]["enum"]="1";
//	filters["u32"]["protocols"]["tcp"]["tcp_control_bits"]["text"][1]="";
	//filters["u32"]["protocols"]["tcp"]["tcp_control_bits"]["enumv"][1]["urg"]["name"]="Urg";
	filters["u32"]["protocols"]["tcp"]["tcp_control_bits"]["urg"]["name"]="Urg";
	//filters["u32"]["protocols"]["tcp"]["tcp_control_bits"]["enumv"][1]["urg"]["text"]="0x20";
	filters["u32"]["protocols"]["tcp"]["tcp_control_bits"]["urg"]["text"][1]="match u8 0x20 0xff at 33";
	filters["u32"]["protocols"]["tcp"]["tcp_control_bits"]["ack"]["name"]="Ack";
	filters["u32"]["protocols"]["tcp"]["tcp_control_bits"]["ack"]["text"][1]="match u8 0x10 0xff at 33";
	filters["u32"]["protocols"]["tcp"]["tcp_control_bits"]["psh"]["name"]="Psh";
	filters["u32"]["protocols"]["tcp"]["tcp_control_bits"]["psh"]["text"][1]="match u8 0x8 0xff at 33";
	filters["u32"]["protocols"]["tcp"]["tcp_control_bits"]["rst"]["name"]="Rst";
	filters["u32"]["protocols"]["tcp"]["tcp_control_bits"]["rst"]["text"][1]="match u8 0x4 0xff at 33";
	filters["u32"]["protocols"]["tcp"]["tcp_control_bits"]["syn"]["name"]="Syn";
	filters["u32"]["protocols"]["tcp"]["tcp_control_bits"]["syn"]["text"][1]="match u8 0x2 0xff at 33";
	filters["u32"]["protocols"]["tcp"]["tcp_control_bits"]["fin"]["name"]="Fin";
	filters["u32"]["protocols"]["tcp"]["tcp_control_bits"]["fin"]["text"][1]="match u8 0x1 0xff at 33";
	filters["u32"]["protocols"]["tcp"]["tcp_control_bits"]["urg_ack_psh_rst_syn_fin"]["name"]="Urg+Ack+Psh+Rst+Syn+Fin";
	filters["u32"]["protocols"]["tcp"]["tcp_control_bits"]["urg_ack_psh_rst_syn_fin"]["text"][1]="match u8 0x3f 0xff at 33";
//	filters["u32"]["protocols"]["tcp"]["tcp_control_bits"]["text"][2]="0xff at 33";

	//UDP protocol
	filters["u32"]["protocols"]["udp"]["name"]="udp";
	filters["u32"]["protocols"]["udp"]["text"][1]="match ip protocol 17 0xff";
	//UDP source port match
	filters["u32"]["protocols"]["udp"]["src_port"]["name"]="source port";
	filters["u32"]["protocols"]["udp"]["src_port"]["text"][1]="match ip sport";
	filters["u32"]["protocols"]["udp"]["src_port"]["value"][1]="port";
	filters["u32"]["protocols"]["udp"]["src_port"]["text"][2]="0xff";
	//UDP destination port match
	filters["u32"]["protocols"]["udp"]["dst_port"]["name"]="destination port";
	filters["u32"]["protocols"]["udp"]["dst_port"]["text"][1]="match ip sport";
	filters["u32"]["protocols"]["udp"]["dst_port"]["value"][1]="port";
	filters["u32"]["protocols"]["udp"]["dst_port"]["text"][2]="0xff";

	//UDP-TCP protocol
	filters["u32"]["protocols"]["udp_tcp"]["name"]="udp/tcp";
	filters["u32"]["protocols"]["udp_tcp"]["text"][1]="";
	//UDP-TCP source port match
	filters["u32"]["protocols"]["udp_tcp"]["src_port"]["name"]="source port";
	filters["u32"]["protocols"]["udp_tcp"]["src_port"]["text"][1]="match ip sport";
	filters["u32"]["protocols"]["udp_tcp"]["src_port"]["value"][1]="port";
	filters["u32"]["protocols"]["udp_tcp"]["src_port"]["text"][2]="0xff";
	//UDP-TCP destination port match
	filters["u32"]["protocols"]["udp_tcp"]["dst_port"]["name"]="destination port";
	filters["u32"]["protocols"]["udp_tcp"]["dst_port"]["text"][1]="match ip sport";
	filters["u32"]["protocols"]["udp_tcp"]["dst_port"]["value"][1]="port";
	filters["u32"]["protocols"]["udp_tcp"]["dst_port"]["text"][2]="0xff";
	
	//ICMP protocol match
	filters["u32"]["protocols"]["icmp"]["name"]="icmp";
	filters["u32"]["protocols"]["icmp"]["text"][1]="match ip protocol 1 0xff";

	//Qdiscs:
	qdiscs["htb"];

	//Classes
	classes["htb"];


}

Value* ConstantValues::getFilters()
{
	return &filters;
}


ConstantValues::~ConstantValues()
{
	instanceFlag=false;
}

ConstantValues* ConstantValues::getInstance()
{
	if(!instanceFlag)
	{
        	single=new ConstantValues();
                instanceFlag=true;
	}
        return single;
}

